package com.muhuahealth.controller;

import com.muhuahealth.entity.PipeReconstructionEntity;
import com.muhuahealth.service.PipeReconstructionService;
import com.muhuahealth.utils.ServerResponse;
import lombok.extern.log4j.Log4j2;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author GSK
 * @version 1.0
 * @date 2021/2/28 15:46
 */
@Log4j2
@Controller
@RequestMapping("/admin/pipeReconstruction")
public class PipeReconstructionController {

    @Autowired
    PipeReconstructionService pipeReconstructionService;

    /**
     * 排水管线展示页面
     * @param request
     * @return
     */
    @GetMapping("")
    public String pipeReconstructionPage(HttpServletRequest request){
        log.info("跳转到排水管线改造页面");
        request.getSession().setAttribute("path","Daily_items2");
        return "/Daily_items2";
    }

    /**
     * 查询结果
     * @param pipeRecons
     * @param model
     * @param session
     * @return
     */
    @RequestMapping(value = "/searchResult",method = RequestMethod.POST)
    @ResponseBody
    public String searchResult(@Param("hutongName") String hutongName,
                               @Param("materialName") String materialName,
                               Model model, HttpSession session){
        PipeReconstructionEntity pipeRecons = new PipeReconstructionEntity();
        pipeRecons.setHutongName(hutongName);
        pipeRecons.setMaterialName(materialName);
        List<PipeReconstructionEntity> list = pipeReconstructionService.getSearchResult(pipeRecons);
        log.info("hutong_name:" + hutongName);
        log.info("material_name:"+ materialName);
        if(list.size() != 0){
//            session.setAttribute("hutongName",pipeRecons.getHutongName());
//            session.setAttribute("materialName",pipeRecons.getMaterialName());
            model.addAttribute("list",list);
//            log.info("胡同名=>" +pipeRecons.getHutongName());
//            log.info("材料名=>" +pipeRecons.getMaterialName());
            log.info("list:" +list);
            return "/Daily_items2::pipe_reconstruction";
        }
        log.error(list);
        return null;
    }
}
